<div>
    <fieldset class="MarginBottom" id="AddForm">
        <legend>Ид издания: <?php echo $this->data['edit_id']; ?></legend>

        <span class="ErrorMessage" data-field="log"></span>

        <div class="RoundBorder MarginBottom" style="background-color: lightyellow;">
            <?php echo $this->ItemBrief()->ToHtml() ?>
        </div>

        <table>
            <tr><td>Дата поступления</td><td><input type="text" id="Date"
                value="<?php echo date('d.m.Y', time()); ?>"/></td></tr>
            <tr><td></td><td class="ErrorMessage" data-field="Date"></td></tr>
            <tr><td>Количество экземпляров</td><td><input type="text" id="NumItems"/></td></tr>
            <tr><td></td><td class="ErrorMessage" data-field="NumItems"></td></tr>
        </table>

        <input type="hidden" id="EditId" value="<?php echo $this->data['edit_id']; ?>"/>
    </fieldset>

    <div class="ControlPanel">
        <button id="Accept">Добавить</button>
        <button id="Cancel">Закрыть</button>
    </div>

    <script id="AddItemScript">
        jsun.run(function() {

        jsun("#Cancel").jsun.event({ onclick: Cancel });
        jsun("#Accept").jsun.event({ onclick: Accept });

        function Cancel() {
            jsun.dialog.active.close();
        }

        function Accept() {
            var param = "u=Edition/AddItem"
                + "&EditId=" + jsun("#EditId").value
                + "&Date=" + jsun("#Date").value
                + "&NumItems=" + jsun("#NumItems").value;


            jsun.json.load(function(p) {
                if (p.STAT == "OK") {
                    var items = p.ID.toString().replace(/,/g, ", ");

                    var list = { tag: "div",
                        body: [
                            { text: "Экземпляры успешно добавленны с номерами: " },
                            { tag: "div", body: [{ text: items }],
                                attr: { 'class': "RoundBorder MarginBottom",
                                    'style': "background-color: lightyellow;" } }]
                    };
                    jsun("#AddForm").parentNode.replaceChild(
                        jsun.dom(list), jsun("#AddForm"));
                    jsun("#Accept").parentNode.removeChild(jsun("#Accept"));
                    jsun("#Cancel").value = "OK";
                } else {
                    jsun.show_err(p);
                }
            }, param);
        }

        });
    </script>
</div>